package com.zrt.pad.commonui.task;

import java.io.BufferedInputStream;
import java.math.BigDecimal;

import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import com.zrt.pad.commonui.SharedApplication;

public class UMSPrintTask extends AsyncTask<String, Object, Object> {


	
	public void printTicket(String swipInfo) {
		
	}
	@Override
	protected Object doInBackground(String... params) {
		JSONObject json = null;
		try {
			json = new JSONObject(params[0]);
		} catch (Exception e) {
			
		}
		if (json != null) {
			String orderId = json.optString("_orderId");
			String txnType = json.optString("txnType");// 消费(SALE)、消费撤销(VOID)、退货(REFUND)
			String batchNo = json.optString("batchNo");// 批次号
			String billsMID = json.optString("billsMID");// 商户编号
			String billsMercName = json.optString("billsMercName");// 商户名称
			String dealDate = json.optString("dealDate");// 交易日期
			String pAccount = json.optString("pAccount");// 卡号
			String amount = json.optString("amount");// 金额
			String refId = json.optString("refId");// 参考号
			String termId = json.optString("termId");// 终端编号
			String acqNo = json.optString("acqNo");// 收单机构
			String issNo = json.optString("issNo");// 发卡行
			String authNo = json.optString("authNo");// 授权码
			
			try {
				BufferedInputStream bis = new BufferedInputStream(
						SharedApplication.context.getAssets().open(
								"printer_logo.png"));
				Bitmap bitmap = BitmapFactory.decodeStream(bis);
				/*U.p.printBitmap(bitmap);
				U.p.println("商户名(MERCHANT NAME):");
				U.p.setFontDouble();
				U.p.println(billsMercName);
				U.p.setFontNormal();
				U.p.println("商户编号(MERCHANT NO):"+billsMID);
				U.p.println("终端号(TERMINAL NO):"+termId);
				U.p.println("操作员号(OPERATOR NO):01");
				U.p.println("收单行(ACQUIRER):"+acqNo);
				U.p.println("发卡行(ISSUER):"+issNo);
				U.p.println("卡号(CARD NO):");
				U.p.setFontDouble();
				U.p.println(pAccount);
				U.p.setFontNormal();
				U.p.println("有效期(EXP DATE):2022/09");
				U.p.println("交易类别(TRANS TYPE):");
				U.p.printlnBig(txnType);
				U.p.println("订单号(ORDER NO):"+orderId);
				U.p.println("批次号(BATCH NO):"+batchNo);
				U.p.printlnBig("凭证号(VOUCHER NO):000464");
				U.p.println("参考号(REFER NO):"+refId);
				U.p.println("授权码(授权码):"+authNo);
				U.p.println("日期/时间(DATE/TIME):" + dealDate);
				U.p.println("交易金额(AMOUNT):");*/
				try {
					amount = new BigDecimal(amount).divide(new BigDecimal(100)).setScale(2).toString();
				} catch (Exception e) {
					
				}
				/*U.p.printlnBig("RMB " + amount);
				U.p.setFontSmall();
				U.p.println("---------");
				U.p.println("本人确认以上交易");
				U.p.println("同意将其计入本卡账户");
				U.p.setFontNormal();
				U.p.printSpaceLine(5);*/
			} catch (Exception e) {
			}
		}
		
		return null;
	}

}
